<?php
if(!interface_exists('XConfigLoader', false)){
	require(XFRAMEWORK_DIR.'/core/config/XConfigLoader.php');
}
final class XBasicConfigLoader implements XConfigLoader{
	public function load($file){
		$result = $this->loadExtensions($file, array(
			'\.php$' => 'XPHPConfigLoader',
			'\.ini$' => 'XINIConfigLoader',
			'\.yaml$' => 'XYAMLConfigLoader',
			'\.xml$' => 'XXMLConfigLoader',
		));
		if($result){
			return $result;
		}
		return array();
	}
	
	public function loadExtensions($file, $extensions){
		foreach($extensions as $key => $value){
			if(!preg_match("/{$key}/i", $file)){
				continue;
			}
			if(!class_exists($value)){
				continue;
			}
			if(!XClassLoader::loader($value)->implementsInterface('XConfigLoader')){
				continue;
			}
			$loader = XFactory::singleton()->get($value);
			return $loader->load($file);						
		}
		return false;	
	}
}
?>